package com.cq.androidtools

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

/**
 * 作者: CQ
 * 日期: 2021-03-26
 * 说明:
 */
fun main() {
//    val list = array2d<Int>(2, 5)
//    for (i in 0 .. 1) {
//        for (j in 0 .. 4) {
//            list[i][j] = 0
//        }
//    }
//    print(list)
//    onE {
//        put("a", "a")
//        put("2", "a")
//        put("3", "a")
//    }
    main11()
}

fun main11() {
    val flow = MutableStateFlow(-1)

    CoroutineScope(Dispatchers.Main).launch {
        flow.collect {
            println(it)
        }
    }

    runBlocking {
        flow.emit(0)
        flow.emit(1)
        flow.emit(2)
        flow.emit(2)
        flow.emit(3)
    }


}

fun onE(params : MutableMap<String, String>.() -> Unit = {}) {

    val map = HashMap<String, String>()
    map.params()
    map.forEach {
        println(it.key + "   " + it.value)
    }
}


class A(var a : String) : Cloneable {
    override fun toString() : String {
        return "A(a='$a')"
    }

    fun onCopy() : A {
        return super.clone() as A
    }

    override fun clone() : A {
        return super.clone() as A
    }
}
